package com.ysd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.entity.Order;
import com.ysd.service.OrderService;
import com.ysd.util.Result;

@Controller
public class OrderController {
	@Autowired
	OrderService orderService;
	
	@RequestMapping("getOrder")
	@ResponseBody
	public Object getOrder(int userId) {
		List<Order> list=orderService.findOrders(userId);
		return list;
	}
	@RequestMapping("getOrderByStatus")
	@ResponseBody
	public Object getOrderByStatus(Order order) {
		List<Order> list=orderService.findOrdersByStatus(order);
		return list;
	}
	
	@RequestMapping("xiuGaiOrder")
	@ResponseBody
	public Object xiuGaiOrder(Order order) {
		int n=orderService.updateOrder(order);
		if (n>0) {
			return Result.toClient("0", "修改成功", null, n);
		} else {
			return Result.toClient("1", "修改失败", null, null);
		}
	}
	
	@RequestMapping("getOrderByWhere")
	@ResponseBody
	public Object getOrderByWhere(Order order) {
		order.setPage((order.getPage()-1)*order.getLimit());
		List<Order> list=orderService.findOrdersByWhere(order);
		int n=orderService.findOrderCount(order);
		if (list!=null) {
			return Result.toClient("0", "查询成功", n, list);
		} else {
			return Result.toClient("1", "查询失败", 0, null);
		}
	}
	@RequestMapping("xgOrderStatus")
	@ResponseBody
	public Object xgOrderStatus(Order order) {
		int n=orderService.updateOrderStatus(order);
		if (n>0) {
			return Result.toClient("0", "发货成功", null, n);
		} else {
			return Result.toClient("1", "发货失败", null, null);
		}
	}
	
	@RequestMapping("addOrders")
	@ResponseBody
	public Object addOrderss(Order order) {
		int n=orderService.findOrders(order);
		if (n>0) {
			return Result.toClient("0", "添加成功", n);
		} else {
			return Result.toClient("1", "添加失败", null);
		}
	}
	
	@RequestMapping("getOrdersssss")
	@ResponseBody
	public Object getOrderByWheres(Order order) {
		List<Order> list=orderService.findOrderByWheres(order);
		return list;
	}
	
	@RequestMapping("updateSta")
	@ResponseBody
	public Object updateSta(int userId) {
		int n=orderService.findOrderSta(userId);
		if (n>0) {
			return Result.toClient("0", "修改成功", n);
		} else {
			return Result.toClient("1", "修改失败", null);
		}
	}

}
